import os
import time
import subprocess
class GPIO:
	def __init__(self, PIN):
		self.PIN = PIN

	def write(self,VAL):
		PATH = '/sys/class/gpio/gpio'+ str(self.PIN) + '/' + 'value'
		with open(PATH, "w") as f:
			f.write(str(VAL))
		return

	def mode(self,MODE):
		PATH = '/sys/class/gpio/gpio'+ str(self.PIN) + '/' + 'direction'
		if (MODE.lower() == 'in'):
			with open(PATH, "w") as f:
				f.write('in')
			
		elif (MODE.lower() == 'out'):
			with open(PATH, "w") as f:
				f.write('out')

		return

	def read(self):
		PATH = '/sys/class/gpio/gpio'+ str(self.PIN) + '/' + 'value'
		with open(PATH, "r") as f:
			x = f.read()
		return x

Ping = GPIO(56)
Ping.mode('in')
dist,count = 0,0
while(True):
	if ((int)(Ping.read())) == 1:
		print 1
	else:
		print 0
	time.sleep(0.1)

#Ping.WRITE(0)
#PING.write(124,['direction','out'])
#PATH_DIR = '/sys/class/gpio/gpio124/direction'
#PATH_VAL = '/sys/class/gpio/gpio124/value'
#f1 = open(PATH_DIR, "w")
#f2 = open(PATH_VAL, "w")
#f1.write('out')
#f1.close()

  #pinMode(pingPin, OUTPUT);
  #digitalWrite(pingPin, LOW);
  #delayMicroseconds(2);
  #digitalWrite(pingPin, HIGH);
  #delayMicroseconds(5);
  #digitalWrite(pingPin, LOW);

  #// The same pin is used to read the signal from the PING))): a HIGH
  #// pulse whose duration is the time (in microseconds) from the sending
  #// of the ping to the reception of its echo off of an object.
  #pinMode(pingPin, INPUT);
  #duration = pulseIn(pingPin, HIGH);

